const Video_Model = require("../models/VideoModel")

const Video_service = {
    video_add: async (data) => {
        await Video_Model.create({
            ...data
        })
    },
    get_list: async (id = 0) => {
        return {
            data: await Video_Model.find().select('-__v').limit(4).skip(id).sort({ publish_time: 'desc' }),
            count: await Video_Model.countDocuments()
        }
    },
    get_one: async (id) => {
        return await Video_Model.findOne({
            _id: id
        }).select("-__v -likes -comment -publish_time -view")
    },
    put_video: async (data) => {
        return await Video_Model.updateOne({
            _id: data._id
        }, {
            ...data
        })
    },
    delete_video: async (id) => {
        return await Video_Model.deleteOne({
            _id: id
        })
    }

}


module.exports = Video_service